<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';

$appid = $_GET['id'];
if($_GET['emailId']){
	$emailId = $_GET['emailId'] + 0;
	$emailUrl = "&emailId=".$emailId;
	$smarty->assign('emailUrl',$emailUrl);
}

$emailId = $_GET['emailId'] + 0 ;
if($emailId > 0){
	//Update to is_read
	$sql = "UPDATE pa_email SET `e_isread` = 1 WHERE e_id = '".$emailId."' AND e_receivedrcid= '".$_SESSION['uid']."'";
	$DB->query($sql);
}

$other = "  AND c.app_ownid = '".$_SESSION[uid]."' ";
if($_GET[recruiter]==1){
$other = " AND c.app_recruitid = '".$_SESSION[uid]."' ";
$replyHide = 1;
$smarty->assign("replyHide",$replyHide);
}

$rs = $DB->fetch_one_array("SELECT  a.jo_id,a.jo_title,a.jo_status,a.jo_copname,b.re_id,b.re_fname,b.re_lname,b.re_nickname, c. * ,d.rc_uname,d.rc_id,b.re_locity,b.re_lostate,b.re_uploadresume,b.re_crtjobtitle,b.re_jobtitle,b.re_nickname,b.re_schoolattend,b.re_desiredpay,b.re_currentpay,b.re_aliasname,b.re_schoolattend,b.re_edulevel,b.re_yearexp,b.re_mgmt,b.re_profit,b.re_detail,b.re_email,b.re_phone1,b.re_prvemployer,b.re_authorize,b.re_prvempstatus,b.re_locountry,b.re_professavilable,b.re_sponsorship
					FROM pa_job AS a, pa_resume AS b, pa_applicant AS c, pa_recuiter AS d
					WHERE c.app_jobid = a.jo_id
					AND c.app_resumeid = b.re_id
					AND (c.app_recruitid = d.rc_id OR c.app_recruitid = 0) AND c.app_id='".$appid."' GROUP BY c.app_id");


if($_GET[tpp] == "posted"){
	$rs  = $DB->fetch_one_array("SELECT a.jo_function,a.jo_id,a.jo_title,a.jo_authorized,a.jo_status,a.jo_copname,a.jo_regtime,a.jo_vdate,b.re_id,b.re_fname,b.re_lname, c. * ,d.rc_uname,d.rc_id,b.re_locity,b.re_lostate,b.re_uploadresume,b.re_crtjobtitle,b.re_jobtitle,b.re_nickname,b.re_schoolattend,b.re_desiredpay,b.re_currentpay,b.re_aliasname,b.re_schoolattend,b.re_edulevel,b.re_yearexp,b.re_mgmt,b.re_profit,b.re_detail,b.re_email,b.re_phone1,b.re_prvemployer,b.re_authorize,b.re_prvempstatus,b.re_locountry,b.re_professavilable,b.re_sponsorship
	FROM pa_job AS a, pa_resume AS b, pa_applicant AS c, pa_recuiter AS d
	WHERE c.app_jobid = a.jo_id
	AND c.app_resumeid = b.re_id
	 AND c.app_id ='".$appid."' $other");
	//submitted & received
	$smarty->assign('submitted','1');

}


if(empty($rs)){
	  echo "<meta http-equiv=\"refresh\" content=\"0;URL=errorall.php?errid=rc_1003\">";
	  exit;
}

if($_GET[submit]==1){
   $DB->query("Update pa_applicant SET `app_submittime`='".time()."' WHERE app_id= '".$appid."' ");
   echo "<meta http-equiv=\"refresh\" content=\"0;URL=applicantdetails.php?id=$appid\">";
   exit;
}

//print_r($rs);
ob_clean();
ob_start();
	   $cpforms->formheader(array('title'=>'', 'name'=>'article'));
	   $view =1;

       if($_GET[view]==1){
			   echo "<tr><td align=left colspan=\"2\"><b>Recruiter and Job Offer Information</b></td></tr>";
			   if($rs[app_submittime]==''){
			   echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Connect with Recruiter? To contact the recruiter you must check this box to display his/her contact information.</td><td  ><input id=\"checksubmit\" type=\"checkbox\" onclick=\"javascript:cksubmit('".$appid."')\" ></td></tr>";	
		   }else{
				echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Recruiter Information </td><td  ><a href=\"recdetail.php?id=$rs[app_recruitid]\">$rs[rc_uname]</a></td></tr>";		   
				echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Information Release Date/Time </td><td  >".@date("m/d/Y h:i:s A",$rs[app_submittime])."</td></tr>";	
				echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Date of Offer </td><td  >".$rs[app_offerdate]."</td></tr>";
				echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Onboard Date </td><td  >".$rs[app_onboarddate]."</td></tr>";
				echo "<tr class=\"firstalt\" nowrap><td width=\"40%\" > Offered Salary </td><td  >$".number_format($rs[app_annualsalary])."</td></tr>";
				 echo "<tr class=\"tbhead\"><td colspan=\"2\" align=\"center\" ><input class=\"bginput button-secondary\" type=\"button\" value=\"Back\" onclick=\"javascript:history.go(-1);\"></td></tr>";

		   }
	   }else{
			 $cpforms->longline(array('title'=>"Applicant Record"));
	   	   $cpforms->gethightext(array('text'=>"Submit Date/Time",'name'=>"username",'only'=>1,'value'=>date("m/d/Y h:i:s A",$rs[app_regtime]),'read'=>"$read",'view'=>"$view"));
		   $cpforms->gethightext(array('text'=>"Applicant Number",'name'=>"app_id",'only'=>1,'value'=>$rs[app_id],'read'=>"$read",'view'=>"$view"));

			 $cpforms->longline(array('title'=>"Applicant Detail"));
			$cpforms->gethightext(array('text'=>"ER Job Req #",'name'=>"username",'only'=>1,'value'=>$rs[app_jobid],'read'=>"$read",'view'=>"$view"));
			//$cpforms->gethightext(array('text'=>"Company Name",'name'=>"copname",'only'=>1,'value'=>$rs[jo_copname],'read'=>"$read",'view'=>"$view"));
			//$cpforms->gethightext(array('text'=>"Job Posted Date",'name'=>"jobregtime",'only'=>1,'value'=>@date("m/d/Y",$rs[jo_regtime]),'read'=>"$read",'view'=>"$view"));
			//$jo_vdate = trim($rs['jo_vdate']) == ''?"N/A":@date("m/d/Y",strtotime($rs[jo_vdate]));
			//$cpforms->gethightext(array('text'=>"Job Valid by Date",'name'=>"copname",'only'=>1,'value'=>$jo_vdate,'read'=>"$read",'view'=>"$view"));
			$cpforms->gethightext(array('text'=>"Job Title",'name'=>"username",'only'=>1,'value'=>$rs[jo_title],'read'=>"$read",'view'=>"$view"));
			
		    $cpforms->longline(array('title'=>"Applicant Detail"));
		   $cpforms->gethightext(array('text'=>"Availability Status",'value'=>$appstatus[$rs[app_status]],'read'=>"$read",'view'=>"$view"));
		   if($rs[app_recruitid]>0){
		   $cpforms->gethightext(array('text'=>"Nick Name",'value'=>$rs[re_nickname],'read'=>"$read",'view'=>"$view"));
		   }
		   if(!($rs[app_owntype] == 'recruiter' && $rs[app_recruitid] > 0)){
			   $cpforms->gethightext(array('text'=>"First Name",'value'=>$rs[re_fname],'read'=>"$read",'view'=>"$view"));
			   $cpforms->gethightext(array('text'=>"Last Name",'value'=>$rs[re_lname],'read'=>"$read",'view'=>"$view"));
			   $cpforms->gethightext(array('text'=>"Email",'value'=>$rs[re_email],'read'=>"$read",'view'=>"$view",'email'=>1));
			   $cpforms->gethightext(array('text'=>"Phone",'value'=>$rs[re_phone1],'read'=>"$read",'view'=>"$view"));
		   }
		   
		   if($_SESSION[usertype]!="employer" && $rs[re_aliasname]!=''){
		   $cpforms->gethightext(array('text'=>"Alias Name",'value'=>$rs[re_aliasname],'read'=>"$read",'view'=>"$view"));
		   }

			$city = ($rs[re_locity] == '')?"":$rs[re_locity];
			$states = ($rs[re_lostate]==0)?"":$state[$rs[re_lostate]];
		   $cpforms->gethightext(array('text'=>"Location",'value'=>$city.", ".$states.", ".$country[$rs[re_locountry]],'read'=>"$read",'view'=>"$view"));
		   if($rs[re_crtjobtitle] <> ''){
		    $cpforms->gethightext(array('text'=>"Current Job Title",'value'=>"<b><font color='blue'>".$rs[re_crtjobtitle]."</font></b>",'read'=>"$read",'view'=>"$view"));
		   }
			$cpforms->gethightext(array('text'=>"Desire Job Title",'value'=>"<b><font color='blue'>".$rs[re_jobtitle]."</font></b>",'read'=>"$read",'view'=>"$view"));
		   $cpforms->gethightext(array('text'=>"Current Annual Base Salary",'value'=>"$".number_format($rs[re_currentpay]),'read'=>"$read",'view'=>"$view"));
		   $cpforms->gethightext(array('text'=>"Desired Annual Base Salary",'value'=>"$".number_format($rs[re_desiredpay]),'read'=>"$read",'view'=>"$view"));
		   if($rs[app_owntype] == 'recruiter'){
			$sql = "SELECT rc_fname,rc_lname FROM pa_recuiter WHERE rc_id =  '".$rs[app_recruitid]."' ";
			$rcInfo = $DB->fetch_one_array($sql);
		   $cpforms->gethightext(array('text'=>"Recruiter Contact",'value'=>"<a href='recdetail.php?id=".$rs[app_recruitid]."' target='_blank'>".$rcInfo[rc_fname]." ".$rcInfo[rc_lname]."</a>",'read'=>"$read",'view'=>"$view"));
		   $cpforms->maketextarea2(array('text'=>"Recruiter Note",'value'=>$rs['app_note'],'read'=>"$read",'view'=>"$view"));
		   } 
		    $cpforms->longline(array('title'=>"Applicant Qualifications"));
		  
		   if(trim($rs[re_schoolattend]) <> ""){
		   $cpforms->gethightext(array('text'=>"Schools Attended",'value'=>$rs[re_schoolattend],'read'=>"$read",'view'=>"$view"));
		   }

		   $_education = ($rs[re_edulevel]==0)?"":$education[$rs[re_edulevel]];
		   $_yearexp = ($rs[re_yearexp]==0)?"":$yearexp2[$rs[re_yearexp]];
		   $_mgmt = ($rs[re_mgmt]==0)?"":$yearexp2[$rs[re_mgmt]];
		   $_profit = ($rs[re_profit]==0)?"":$yearexp2[$rs[re_profit]];
			
		   if($rs[re_edulevel]>1){
		   $cpforms->gethightext(array('text'=>"Highest Degree",'value'=>$_education,'read'=>"$read",'view'=>"$view"));
		   }
		   if($rs[re_yearexp]>1){
		   $cpforms->gethightext(array('text'=>"Years of Relevant Work Experience",'value'=>$_yearexp,'read'=>"$read",'view'=>"$view"));
		   }
		   if($rs[re_mgmt]>1){
		   $cpforms->gethightext(array('text'=>"Years of People Management Experience",'value'=>$_mgmt,'read'=>"$read",'view'=>"$view"));
		   }
		   if($rs[re_profit]>1){
		   $cpforms->gethightext(array('text'=>"Years of Profit & Loss Responsibility ",'value'=>$_profit,'read'=>"$read",'view'=>"$view"));
		   }

		   $rs[app_resumedetail] = str_replace("<!--[if !supportLists]-->","",$rs[app_resumedetail]);
		   $rs[app_resumedetail] = str_replace("<!--[endif]-->","",$rs[app_resumedetail]);
		   	$fileurl = ($rs['app_newresume'] != '')? './uploadfiles/resumes/'.$rs['app_newresume']:'./uploadfiles/resumes/'.$rs['re_uploadresume'];
			if($rs['app_newresume'] == '' && $rs['re_uploadresume'] == '') $fileurl = '';
			if($rs['app_incoldresume'] <> 1 && $rs['re_uploadresume'] != '' && $rs['app_newresume'] == '') $fileurl = '';
		   $cpforms->maketextarea2(array('text'=>"Resume Details",'value'=>($rs[app_resumedetail]),'read'=>"$read",'view'=>"$view",'fileurl'=>$fileurl));
			   
		    $cpforms->longline(array('title'=>"Work Status, Employment and Professional References"));
		   $cpforms->gethightext(array('text'=>"Authorized to Work Locations",'value'=>$rs[re_authorize],'read'=>"$read",'view'=>"$view"));  
		   $cpforms->gethightext(array('text'=>"Three Previous Employers",'value'=>$rs[re_prvemployer],'read'=>"$read",'view'=>"$view"));
		   $cpforms->gethightext(array('text'=>"Previous Employment Status Checked?",'value'=>$YESNO[$rs[re_prvempstatus]],'read'=>"$read",'view'=>"$view"));
		   $cpforms->gethightext(array('text'=>"Three Professional References Available?",'value'=>$YESNO[$rs[re_professavilable]],'read'=>"$read",'view'=>"$view"));
          
		  
		   if($_SESSION[usertype]!="employer"){$page_return = "myjobs.php"; }else{$page_return = "mypostjobs.php"; }
		   echo "<tr ><td colspan=\"2\" align=\"center\" ><input class=\"bginput button-secondary\" type=\"button\" value=\"Back\" onclick=\"javascript:history.go(-1);\">";
		   if($replyHide <> 1){
			  echo "<input class=\"bginput button-secondary\" type=\"button\" value=\"Reply\" onclick=\"location.href='applicationreply.php?rid=".$appid.$emailUrl."'\" />";
		   }
		   echo "</td></tr>";
	   }
		echo "</table></td></tr></table>\n";
	   $content = ob_get_contents();
       ob_end_clean();


$smarty->assign("content",$content);
$smarty->assign("rid",$appid);

$smarty->compile_check = true;

$smarty->display('header.tpl');

$smarty->display('allleft.tpl');
$smarty->display('applicantdetails.tpl');
$smarty->display('allright.tpl');
$smarty->display('footer.tpl');
?>